// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import vueAwesomeSwiper from 'vue-awesome-swiper'
//import Loading from '@/components/loading/loading.js'
import NProgress from 'nprogress'
import Vuex from 'vuex'
import 'nprogress/nprogress.css'
import router from './router'
import store from './store';
import ElementUI from 'element-ui'
import 'swiper/dist/css/swiper.css'
import animate from 'animate.css'
import 'element-ui/lib/theme-chalk/index.css'
import preventReClick from './store/preventReClick'
import echarts from 'echarts'

import BaiduMap from 'vue-baidu-map'
import Distpicker from 'v-distpicker'

import VueDND from "awe-dnd";
Vue.use(VueDND);
import vcolorpicker from "vcolorpicker";
Vue.use(vcolorpicker);

Vue.component('v-distpicker', Distpicker)
Vue.use(BaiduMap, {
	ak: 'F03lq7f1aDdDfGoQcVrRadknpCYEb7DO'
})
import Validator from 'vue-validator';
Vue.use(Validator, {
	change: event
});
// import FileSaver from "file-saver";
// import XLSX from "xlsx";
// import "@/style/index.scss"; // wen_snt 全局样式
// import "@/style/style.css";
// import "@/style/form.scss"; // 主表格样式
// import "@/style/common.scss";
// Vue.use(outPdf);
//Vue.use(Loading)
import seeImage from './components/seeImage'
Vue.use(seeImage);
Vue.use(NProgress)
Vue.use(Vuex)
Vue.use(ElementUI)
Vue.use(animate)
Vue.use(echarts)
Vue.use(vueAwesomeSwiper);
Vue.use(echarts);

import china from 'echarts/map/json/china.json'
echarts.registerMap('china', china)
import axios from 'axios'
Vue.prototype.axios = axios;

Vue.config.productionTip = false;
Vue.prototype.WebVideoCtrl = Window.WebVideoCtrl
new Vue({
	el: '#app',
	router,
	store,
	data: function() {
		return {
			PAGE_TITLE: ''
		}
	},
	components: {
		App
	},
	template: '<App/>'
})
router.beforeEach((to, from, next) => {
	if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
		if (sessionStorage.getItem('loginstatus')) { // 判断本地是否存在access_token

			next()
		} else {
			// 未登录,跳转到登陆页面，并且带上 将要去的地址，方便登陆后跳转。
			next({
				path: '/',
				query: {
					referrer: to.fullPath
				}
			})
		}
	} else {
		next()
	}
})


export default {
	install(Vue) {
		// 防重复点击(指令实现)
		Vue.directive('preventReClick', {
			inserted(el, binding) {
				el.addEventListener('click', () => {
					if (!el.disabled) {
						el.disabled = true
						setTimeout(() => {
							el.disabled = false
						}, binding.value || 1000)
					}
				})
			}
		})
	}
}
